package cn.bookcycle.panda.user.util;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class PatternUtil {
    private final String RULE_EMAIL = "^\\w+((-\\w+)|(\\.\\w+))*\\@[A-Za-z0-9]+((\\.|-)[A-Za-z0-9]+)*\\.[A-Za-z0-9]+$";
    private final String RULE_ACCOUNT="^[a-zA-Z]{1}[a-zA-Z0-9_]{5,15}$";
    private final String RULE_PASSWORD="^[a-zA-Z0-9]{8,20}$";
    private final String RULE_TELEPHONE="^((13[0-9])|(14[5,7])|(15[0-3,5-9])|(17[0,3,5-8])|(18[0-9])|166|198|199|(147))\\\\d{8}$";;

    public  boolean checkEmail(String email) {
        Pattern p = Pattern.compile(RULE_EMAIL);
        Matcher m = p.matcher(email);
        return m.matches();
    }
    public boolean checkAccount(String account) {
        Pattern p = Pattern.compile(RULE_ACCOUNT);
        Matcher m = p.matcher(account);
        return m.matches();
    }
    public boolean checkCredential(String credential) {
        Pattern p = Pattern.compile(RULE_PASSWORD);
        Matcher m = p.matcher(credential);
        return m.matches();
    }
    public boolean checkTelephone(String telephone){
        Pattern p = Pattern.compile(RULE_TELEPHONE);
        Matcher m = p.matcher(telephone);
        return m.matches();
    }
}
